<template>
  <div id="team"> 

     <div  style="display:flex;margin-bottom:10px;align-items: center;">
            <img class="top_img" src="@/assets/images/a8.png" style="width:35px;height:35px;margin-right:10px;"/>
            <div style="line-height: 40px;font-weight:bold:">团队管理</div>
     </div> 

 <el-form ref="form" :model="form" label-width="80px">  

   <div style="display:flex;align-items: center;">
          <div style="width:50px;text-align-last: justify;margin-top:-12px;font-size: 14px;color: #606266;margin-right:0px;">查询项</div>
              <el-form-item label="手机号码" >
                <el-input v-model="form.phone" placeholder="姓名/手机号" style="width:140px;"></el-input>
              </el-form-item>    
          <el-row  style="display:flex;">            
              <el-row  style="display:flex;"> 
                  <el-form-item label="好友区间" label-width="80px" >
                        <div style="display: flex;">
                            <el-input style="width:80px;" v-model.number="form.friend_min" placeholder=""></el-input>
                            <div style="width:20px;height:40px;line-height:40px;text-align: center;"> - </div>
                            <el-input  style="width:80px;" v-model.number="form.friend_max" placeholder=""></el-input>
                        </div>
                  </el-form-item>   
                  <el-form-item label="团队区间" label-width="80px" >
                        <div style="display: flex;">
                            <el-input style="width:80px;" v-model.number="form.team_min" placeholder="" disabled></el-input>
                            <div style="width:20px;height:40px;line-height:40px;text-align: center;"> - </div>
                            <el-input  style="width:80px;" v-model.number="form.team_max" placeholder="" disabled></el-input>
                        </div>
                  </el-form-item>  
                  <el-form-item label="贡献查询" label-width="80px" >
                        <div style="display: flex;">
                            <el-input style="width:80px;" v-model.number="form.gx_min" placeholder="" disabled></el-input>
                            <div style="width:20px;height:40px;line-height:40px;text-align: center;"> - </div>
                            <el-input  style="width:80px;" v-model.number="form.gx_max" placeholder="" disabled></el-input>
                        </div>
                  </el-form-item>       
                </el-row>
         </el-row>
        <div class="buttoon_box">
            <div class="buttoon_box_item"  style="margin-left:10px;background:#FFC600;color:white;" @click="search_but1()">确 定</div>
            <div class="buttoon_box_item" style="margin-left:10px;border:1px solid #D9D9D9;" @click="refresh_but()">清 空</div>    
        </div>

    </div>

     <div style="display:flex;align-items: center;">
            <div style="width:50px;text-align-last: justify;margin-top:-12px;font-size: 14px;color: #606266;">筛选项</div>
             <el-form-item  label="团长类别" >
                <el-select  v-model="form.select_num" placeholder="团长类别"  style="width:140px;">
                    <el-option  v-for="(item,index) in select_data" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>   

            <div class="buttoon_box">
                <div class="buttoon_box_item"  style="margin-left:10px;background:#FFC600;color:white;"  @click="search_but2()">确 定</div>
                <div class="buttoon_box_item" style="margin-left:10px;border:1px solid #D9D9D9;" @click="refresh_but()">清 空</div>    
            </div>

      </div>

     <el-row>   
         <el-col :span="24" style="text-align: right;margin-bottom:10px;">
           <el-button class="custom_color_button1" type="primary" @click="fictitious_but()"><img class="custom_color_button1_img" src="@/assets/images/but_bg2.png" />添加虚拟团长</el-button>
           <el-button class="custom_color_button1" type="primary" @click="mtk1_but"><img class="custom_color_button1_img" src="@/assets/images/but_bg2.png" />添加团长</el-button>
        </el-col>  
    </el-row>
   </el-form>

   <!-- 渲染数据list -->
   <team-list :datalist="datalist" > </team-list>


    <!-- 添加团长 -->
        <el-dialog title="添加团长" :visible.sync="mtk1"  width="400px">
            <div style="width:100%;"> 

            <el-form ref="form"   label-width="100px" style="width:100%;">
                <el-form-item label="" label-width="0px" >
                    <el-input v-model="form.telphone" placeholder="手机号"></el-input>
                </el-form-item>                                   
            </el-form>

                <div style="text-align: center;width:50%;margin:auto;margin-top:30px;">
                    <el-button type="primary" style="width:100%;" @click="mtk1_but_qr">确认</el-button>
                </div>

            </div> 
        </el-dialog>


          <!-- 添加虚拟团长 -->
        <el-dialog title="添加虚拟团长" :visible.sync="fictitious_mtk"  width="500px">
            <div style="width:100%;"> 

           <el-form ref="form"  label-width="80px">  
                <el-row>   
                    <el-col :span="24" style="display:flex;">
                        <el-form-item label-width="0px" >
                            <el-input v-model="fictitious_form.phone" placeholder="手机号" class="search"></el-input>
                        </el-form-item>

                        <div class="custom_button" @click="fictitious_search()"></div>
                    </el-col>               
                </el-row>
                 <div style="width:100%;" v-if="fictitious_form.show"> 

                    <div style="display:flex;align-items: center;margin-top:10px;">       
                        <div class="box1" >帐号</div>
                        <div style="padding:0px 15px;"></div>
                        <div class="box1" >所属团队</div>
                    </div>

                    <div style="display:flex;align-items: center;margin-top:10px;">
                     
                    <div class="box">
                     
                        <img  v-if="conter.self_icon"  style="width: 50px; height: 50px" :src="urlimg + conter.self_icon" /> 
                           <img  v-else src="@/assets/images/login_bg1.png" />
                        <div class="box_item">
                            <span>{{ conter.self_username }}</span>
                            <span>{{ conter.self_telphone }}</span>
                        </div>
                    </div>

                    <div style="padding:0px 15px;"><i class="el-icon-right"></i></div>

                    <div class="box">                      
                        <img v-if="conter.team_icon"  style="width: 30px; height: 30px" :src="urlimg + conter.team_icon" /> 
                        <img  v-else src="@/assets/images/login_bg1.png" />
                        <div class="box_item">
                            <span>{{ conter.team_username }}</span>
                            <span>{{ conter.team_telphone }}</span>
                        </div>
                    </div>

                  </div>
                    <div style="text-align: center;width:50%;margin:auto;margin-top:30px;">
                          <el-button type="primary" class="custom_color_button" style="width:100%;" @click="fictitious_qr_but()">确认</el-button>
                    </div>
                
               </div>
            </el-form>

         

            </div> 
        </el-dialog>

      
   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>


     <el-dialog title="用户验证" :visible.sync="user_test.user_mtk"  width="400px" >
          <el-form ref="form" :model="user_test"  label-width="100px" style="width:100%;">
                <el-form-item label="" label-width="0px">
                    <el-input v-model="user_test.password" placeholder="二级密码" ></el-input>
                </el-form-item>
                <el-form-item label="" label-width="0px" >
                    <div style="display:flex;">
                        <el-input v-model="user_test.phone" placeholder="手机验证码" style="flex:1;"></el-input>
                         <el-button class="code_but1 custom_color_button" type="primary"  @click="getCode_yz()" :disabled="user_test.disabled" style="margin-left:10px;">
                          {{ user_test.codeText }}
                        </el-button>
                    </div>
                </el-form-item>
                <div style="text-align: center;width:50%;margin:auto;margin-top:20px;">
                  <el-button type="primary" class="custom_color_button" style="width:100%;" @click="user_mtk_but">确认</el-button>
                </div>
         </el-form>
   </el-dialog> 

    

      
  </div>
</template>

<script>
import TeamList from '@/view/Member/TeamList'
export default {
  name: 'team',
  data () {
    return {
        datalist:[],
        page:1,
        count:0,
        form:{
           phone:'',
           friend_min:'',
           friend_max:'',
           team_min:'',
           team_max:'',
           gx_min:'',
           gx_max:'',
           select_num:'',
           telphone:'',
        },
        select_data:[{"id":0,"name":"全部"},{"id":1,"name":"实际"},{"id":2,"name":"虚拟"}],
        mtk1:false,
        user_test:{  //用户判定
            user_mtk:false, //用户判定模态狂
            codeText:'获取验证码', //获取验证码字
            totalTime:60,  //获取验证码秒
            disabled:false, //禁用获取验证码
            password:'', //二级密码
            phone:'',  //验证码
        },

        fictitious_mtk:false,
        fictitious_form:{
           phone:'',
           show:false,
        },
        conter:{
          self_icon:'',
          self_telphone:'',
          self_uid:'',
          self_username:'',
          team_icon:'',
          team_telphone:'',
          team_username:'',
        }

    }
  },
 components:{
    TeamList
  },
  created(){
      this.list_fun()
  },
  mounted (){
    
  },
  methods: {
      list_fun(){
          this.post("/leader/listOfData", {
              page:this.page,
              account:this.form.phone,
              type:this.form.select_num,
              friend_min:this.form.friend_min,
              friend_max:this.form.friend_max,
              team_min:this.form.team_min,
              team_max:this.form.team_max,
	        }).then(res => {
            this.count = res.result.count
            this.datalist = res.result.list
            console.log(res)
         })
      },
     mtk1_but(){
          // this.mtk1 = true
           this.user_test.user_mtk = true
          this.form.telphone = ''
     },
     user_mtk_but(){
        this.getCode_yz_qr().then(res => {
            console.log(res)
            if(res == 1){
                this.mtk1 = true
            }
        })
  
    },
     mtk1_but_qr(){
       this.post("/team/createLeader", {
            telphone:this.form.telphone
	    }).then(res => {

            if(res.error_code == 0){
               this.open1(res.result,'success')  //提示框
               this.mtk1 = false
                this.list_fun()
            }else {
              this.open1(res.message,'warning')
           }
      
        })

     },
     fictitious_but(){
         this.fictitious_mtk = true
     },
     fictitious_search(){
        this.post("/goldbean/selectDetails", {
              telphone:this.fictitious_form.phone,
	        }).then(res => {
              //console.log(res)
              if(res.error_code == 0){
                        this.fictitious_form.show = true
                        this.conter.self_icon = res.result.self_icon
                        this.conter.self_telphone = res.result.self_telphone
                        this.conter.self_uid = res.result.self_uid
                        this.conter.self_username = res.result.self_username
                        this.conter.team_icon = res.result.team_icon
                        this.conter.team_telphone = res.result.team_telphone
                        this.conter.team_username =res.result.team_username
                }else {
                      this.open1(res.message,'warning')
                      this.conter={
                            self_icon:'',
                            self_telphone:'',
                            self_uid:'',
                            self_username:'',
                            team_icon:'',
                            team_telphone:'',
                            team_username:'',
                        }
                      this.fictitious_form.show = false
             }
         })
     },
     fictitious_qr_but(){
        this.post("/goldbean/addViceLeader", {
               uid:this.conter.self_uid,
	        }).then(res => {
                //console.log(res)
             if(res.error_code == 0){
                        this.open1(res.result,'success') 
                        this. conter={
                            self_icon:'',
                            self_telphone:'',
                            self_uid:'',
                            self_username:'',
                            team_icon:'',
                            team_telphone:'',
                            team_username:'',
                        }
                        this.fictitious_form.phone = ''
                        this.fictitious_form.show = false
                        this.fictitious_mtk = false
                        this.list_fun()
                }else {
                      this.open1(res.message,'warning') 
                }

         })
     },
     search_but1(){
         this.page = 1
         this.list_fun()
     },
     search_but2(){
         this.page = 1
         this.list_fun()
     },
     refresh_but(){
         this.form={
           phone:'',
           friend_min:'',
           friend_max:'',
           team_min:'',
           team_max:'',
           gx_min:'',
           gx_max:'',
           select_num:'',
           telphone:'',
        }
         this.page = 1
         this.list_fun()
     },
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>
.box{
    width: 200px;
    display: flex;
    border: 1px solid #DCDFE6;
    border-radius: 5px;
    padding:10px;
}
.box1{
    width: 200px;
    display: flex;
    padding:0px 10px;
    text-align: center;
}
.box>img{
    width: 50px;
    height: 50px;
    border-radius: 50%;
}
.box_item{
    flex: 1;
    margin-left:10px;
}
.box_item>span{
   display: block;
}
</style>
